﻿using System;

namespace RexToy.UI.Controls
{
    public class CollapseBlockGroup : Container
    {
        public CollapseBlockGroup()
        {
            this.__domNode = RexToy.UI.Controls.DomNode.Create(new DomNodeCreateOptions()
            {
                tag = Tag.Div,
                hashName = "container",
                className = "ui-collapsible-set"
            });
        }

        public void AppendControl(CollapseBlock block)
        {
            block.AttachEvent("onclick", new Action<object>(this.CollapseChange).Bind(this));
            this.Super(block);
        }


        private void CollapseChange(object sender)
        {
            CollapseBlock c = sender as CollapseBlock;
            if (c.Collapse)
            {
                for (var i = 0; i < this.__controls.Length; i++)
                {
                    var cb = this.__controls[i] as CollapseBlock;
                    if (sender == cb)
                        continue;
                    else
                        cb.Collapse = false;
                }
            }
        }
    }
}
